package com.hzqy.service.statistics;

import com.hzqy.persistence.dao.statistics.DivideUserBillDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.UserBillVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DivideUserBillServiceBean extends GenericServiceBean<PmsUserVo, DivideUserBillDao, Integer>{
	private static final long serialVersionUID = 1L;
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private DivideUserBillDao divideUserBillDao;

	@Override
	public DivideUserBillDao getEntityDao() {
		return divideUserBillDao;
	}
	public Map<String,Object> selectUserBillList(UserBillVo userBillVo, int curPage,
			int pageSize) {
		if(!"null".equals(userBillVo.getBeginDate()) &&!"".equals(userBillVo.getBeginDate()) ) {
			userBillVo.setBeginDate(userBillVo.getBeginDate()+" 00:00:00");
		}
		if(!"null".equals(userBillVo.getEndDate()) &&!"".equals(userBillVo.getEndDate()) ) {
			userBillVo.setEndDate(userBillVo.getEndDate()+" 23:59:59");
		}
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = divideUserBillDao.selectUserBillCount(userBillVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_ub_serverid", userBillVo.getF_ub_serverid());
			map.put("f_ub_productid", userBillVo.getF_ub_productid());
			map.put("f_ub_parentid", userBillVo.getF_ub_parentid());
			map.put("f_ub_productCode",userBillVo.getF_ub_productCode());
			map.put("f_ub_type", userBillVo.getF_ub_type());
			map.put("types", userBillVo.getTypes());
			String[] typesArr = userBillVo.getTypes().split(",");
			map.put("typesArr", typesArr);
			map.put("f_ui_resolution", userBillVo.getF_ui_resolution());
			map.put("beginDate", userBillVo.getBeginDate());
			map.put("endDate", userBillVo.getEndDate());
			map.put("f_ub_source", userBillVo.getF_ub_source());
            map.put("f_ub_orgId", userBillVo.getF_ub_orgId());
			List<UserBillVo> results = divideUserBillDao.selectUserBillList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<UserBillVo>());
		}
		return map;
	}
	public Map<String,Object> selectExcelList(UserBillVo userBillVo) {
		if(!"null".equals(userBillVo.getBeginDate()) &&!"".equals(userBillVo.getBeginDate()) ) {
			userBillVo.setBeginDate(userBillVo.getBeginDate()+" 00:00:00");
		}
		if(!"null".equals(userBillVo.getEndDate()) &&!"".equals(userBillVo.getEndDate())) {
			userBillVo.setEndDate(userBillVo.getEndDate()+" 23:59:59");
		}
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = divideUserBillDao.selectExcelCount(userBillVo);
		System.out.println("excel = "+rowCount);
		map.put("total", rowCount);
		if(rowCount > 0) {
			map.put("f_ub_serverid", userBillVo.getF_ub_serverid());
			map.put("f_ub_productid", userBillVo.getF_ub_productid());
			map.put("f_ub_parentid", userBillVo.getF_ub_parentid());
			map.put("f_ub_productCode",userBillVo.getF_ub_productCode());
			map.put("f_ub_type", userBillVo.getF_ub_type());
            map.put("types", userBillVo.getTypes());
			map.put("f_ui_resolution", userBillVo.getF_ui_resolution());
			map.put("beginDate", userBillVo.getBeginDate());
			map.put("endDate", userBillVo.getEndDate());
			map.put("f_ub_source", userBillVo.getF_ub_source());
			map.put("f_ub_orgId", userBillVo.getF_ub_orgId());
			List<UserBillVo> results = divideUserBillDao.selectExcelList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<UserBillVo>());
		}
		return map;
	}
}
